package com.hubujun.driverlicense;

import android.app.Application;
import android.content.pm.ApplicationInfo;
import android.graphics.Bitmap;
import android.os.Handler;
import android.os.Looper;

import com.hubujun.driverlicense.db.AccountStorage;
import com.hubujun.driverlicense.util.FileUtils;
import com.hubujun.driverlicense.util.Ln;
import com.hubujun.driverlicense.util.MobileUtils;
import com.hubujun.driverlicense.util.Util;
import com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import com.nostra13.universalimageloader.core.assist.QueueProcessingType;

import java.io.File;

/**
 * Created by Administrator on 2016/5/28 0028.
 */
public class DLApplication extends Application {

    public static Thread mMainThread = Looper.getMainLooper().getThread();
    public static Handler mMainHandler = new Handler(Looper.getMainLooper());


    @Override
    public void onCreate() {
        super.onCreate();

        ApplicationContext.init(getApplicationContext());

        DLCore.init();

        initImageLoader();
    }

    private void initImageLoader() {
        DisplayImageOptions.Builder builder = new DisplayImageOptions.Builder();
        builder.cacheInMemory(true);
        builder.cacheOnDisc(true);
        builder.bitmapConfig(Bitmap.Config.RGB_565);
        builder.imageScaleType(ImageScaleType.EXACTLY);
//        builder.showImageForEmptyUri(R.drawable.ic_default_radio_cover);
        // builder.showImageOnFail(R.drawable.ic_default_radio_cover);

        ImageLoaderConfiguration.Builder config = new ImageLoaderConfiguration.Builder(ApplicationContext.getContext());
        config.defaultDisplayImageOptions(builder.build());
        config.threadPoolSize(5);
        config.threadPriority(Thread.NORM_PRIORITY - 2);
        config.tasksProcessingOrder(QueueProcessingType.FIFO);
        config.denyCacheImageMultipleSizesInMemory();
        int availableMemorySize = MobileUtils.getAvailableMemorySize();
        config.memoryCache(new LruMemoryCache(availableMemorySize > 4 * 64 * 1024 * 1024 ? 64 * 1024 * 1024 : availableMemorySize / 4));

        if ((ApplicationInfo.FLAG_DEBUGGABLE & ApplicationContext.getContext().getApplicationInfo().flags) != 0) {
            config.writeDebugLogs();
        }

        ImageLoader.getInstance().init(config.build());
    }

}
